package com.tcode.dao;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.jdbc.core.JdbcTemplate;

import com.tcode.bean.Userbean;
import com.tcode.util.ConnectionUtil;

public class UserDaoImp implements IUserDao {
	
	private QueryRunner runner;
	
	private ConnectionUtil con;
	
	
	public QueryRunner getRunner() {
		return runner;
	}


	public void setRunner(QueryRunner runner) {
		this.runner = runner;
	}


	public void setCon(ConnectionUtil con) {
		this.con = con;
	}


	@Override
	public void save(String name,String phone){
		// TODO Auto-generated method stub
		try {
			runner.update(con.getThreadLocalConnection(), "insert into sys_user_t (uname,phone) values (?,?)",name,phone);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void update(String name,int id){
		try {
			runner.update(con.getThreadLocalConnection(), "update sys_user_t set uname=? where uid = ?",name,id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


	@Override
	public List<Userbean> selectUser() {
		// TODO Auto-generated method stub
		List<Userbean> list=null;
		try {
			
			list=runner.query(con.getThreadLocalConnection(), "select * from sys_user_t", new BeanListHandler<Userbean>(Userbean.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	

}
